package com.xcity.game.combat.skill.impl;

import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.CombatUtils;
import com.xcity.game.combat.Round;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.combat.buff.CombatBuff;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.skill.Skill;

/**
 * 无心插柳<br/>
 * 攻击敌方造成{0}%的技能伤害，并增加我方随机一名队员{1}%攻击力，持续{2}回合
 * @author yang.li
 *
 */
public class COMBAT_SKILL_90128 extends CombatSkill {

	public COMBAT_SKILL_90128(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
		CombatUnit source = action.unit;
		CombatUnit target = action.target.getDefenseUnit(source.getIndex());
		if (target == null) {
			return;
		}
		ActionEffect eff = action.addTarget(target);
		CombatUtils.calcMagicAttack(eff, skill.getParameter(0) / GameStaticConfig.percentBase);
		
		target = source.getTeam().getUnitRandomly();
		action.addBuff(new BUFF(skill, target));
	}
	
	static class BUFF extends CombatBuff {
		int oldAttackPower;
		public BUFF(Skill skill, CombatUnit owner) {
			super(skill.getTemplate().getCombatBuff(), owner, (int) skill.getParameter(2));
			active = true;
			int power = (int) owner.getAttackPower();
			oldAttackPower = power;
			power += power * skill.getParameter(1) / GameStaticConfig.percentBase;
			owner.setAttributeValue(CombatAttributeType.ATTACK_POWER, power);
		}
		@Override
		public void roundEnd(Round round) {
			super.roundEnd(round);
			if (state == STATE_REMOVED) {
				owner.setAttributeValue(CombatAttributeType.ATTACK_POWER, oldAttackPower);
			}
		}
	}

}
